package com.loong.seller.handler;

import com.loong.common.domain.BaseQuery;
import com.loong.common.domain.Pager;
import com.loong.common.utils.TransformUtils;
import com.loong.seller.business.ShopContactBusiness;
import com.loong.seller.common.backend.param.ShopContactParam;
import com.loong.seller.common.backend.param.ShopContactQueryParam;
import com.loong.seller.common.backend.result.ShopContactResult;
import com.loong.seller.common.forehead.param.ShopContactQueryForeheadParam;
import com.loong.seller.common.forehead.result.ShopContactForeheadResult;
import com.loong.seller.model.ShopContact;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 店铺联系服务
 * @Author: hzp
 * @Date: 2020-10-26 13:38
 */
@Component
public class ShopContactHandler {
    @Resource
    private ShopContactBusiness shopContactBusiness;

    /**
     * 保存店铺联系信息
     * @param param 店铺联系方式信息
     */
    public void save(ShopContactParam param){
        shopContactBusiness.save(TransformUtils.transform(param, ShopContact.class));
    }

    /**
     * 更新店铺联系信息
     * @param param 店铺联系方式信息
     */
    public void update(ShopContactParam param){
        shopContactBusiness.updateByPrimaryKeySelective(TransformUtils.transform(param, ShopContact.class));
    }

    /**
     *根据id删除店铺联系信息
     * @param id 店铺联系id
     */
    public void deleteById(Long id){
        shopContactBusiness.deleteById(id);
    }


    /**
     *根据店铺id删除店铺联系信息
     * @param shopId 店铺id
     */
    public void deleteByShopId(Long shopId){
        shopContactBusiness.deleteByCondition(shopId);
    }
    /**
     * 分页查询
     * @param baseQuery 分页对象
     * @param param 分页条件
     * @return
     */
    public Pager<ShopContactResult> pageQuery(BaseQuery baseQuery, ShopContactQueryParam param){
        Pager<ShopContact> manageApisPager = shopContactBusiness.pageQuery(baseQuery, () -> shopContactBusiness.query(param));
        return TransformUtils.transformPage(manageApisPager, ShopContactResult.class);
    }

    /**
     * 分页查询 c端使用
     * @param param 分页条件
     * @return
     */
    public Pager<ShopContactForeheadResult> pageQuery(ShopContactQueryForeheadParam param){
        Pager<ShopContact> manageApisPager = shopContactBusiness.pageQuery(param, () -> shopContactBusiness.query(TransformUtils.transform(param,ShopContactQueryParam.class)));
        return TransformUtils.transformPage(manageApisPager, ShopContactForeheadResult.class);
    }


    /**
     * 根据店铺id 查找联系方式
     * @param shopId 店铺id
     * @return
     */
    public List<ShopContactResult> findContactByShopId(Long shopId) {
        List<ShopContact> resultList = shopContactBusiness.findAllBy("shopId", shopId);
        return TransformUtils.transformList(resultList, ShopContactResult.class);
    }

    /**
     * 根据店铺id 查找联系方式 c端使用
     * @param shopId 店铺id
     * @return
     */
    public List<ShopContactForeheadResult> FindContactByShopIdToForehead(Long shopId) {
        List<ShopContact> resultList = shopContactBusiness.findAllBy("shopId", shopId);
        return TransformUtils.transformList(resultList, ShopContactForeheadResult.class);
    }
}
